package com.foolishbird.sdk.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.foolishbird.sdk.core.HttpEngineApi;
import com.foolishbird.sdk.params.FloatKefuResponseParams;
import com.foolishbird.sdk.params.RedBindedResponseParams;
import com.foolishbird.sdk.params.ResponseParams;
import com.foolishbird.sdk.params.bean.RedBindedInfo;
import com.foolishbird.sdk.params.bean.State;
import com.foolishbird.sdk.ui.assist.OnFinishActivityListener;
import com.foolishbird.sdk.utils.MyFragmentManger;
import com.foolishbird.sdk.utils.ResUtils;
import com.foolishbird.sdk.utils.WL;

import java.text.SimpleDateFormat;
import java.util.List;


public class RedpackageAlipayFragment extends BaseHttpFragment implements View.OnClickListener {



    private TextView titleTxt;

    private ImageView backView;
    private EditText accountEdit,NameEdit;
    private Button confirmBtn;

    public static final RedpackageAlipayFragment newInstance(Bundle bundle) {
        RedpackageAlipayFragment fragment = new RedpackageAlipayFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        int resource = ResUtils.getLayoutIdentifier(getActivity(), "fb_redpackage_alipay");
        View contentView =inflater.inflate(resource,null);
        backView = contentView.findViewById(getViewIdentifier("fb_fragment_login_back"));
        backView.setOnClickListener(this);
        titleTxt = contentView.findViewById(getViewIdentifier("fb_fragment_float_title"));
        titleTxt.setText("支付宝账号绑定");
        accountEdit = contentView.findViewById(getViewIdentifier("redpakcage_alipay_account"));
        NameEdit = contentView.findViewById(getViewIdentifier("redpakcage_alipay_name"));
        confirmBtn = contentView.findViewById(getViewIdentifier("redpakcage_alipay_confirm"));
        confirmBtn.setOnClickListener(this);
//        HttpEngineApi.getInstance().redpackageCommon("my_bind",requestCallbackHandler(RedBindedResponseParams.class));
        return contentView;

    }

    private List<RedBindedInfo> myNoticeList;

    @Override
    public void onAsyncRequestResult(int flag, ResponseParams response, Object... params) {
        super.onAsyncRequestResult(flag, response, params);
        if (response != null) {
            int code = response.getState().getCode();
            if (State.SUCCESS == code) {
                 if(flag == deleteTaskId){
                   Toast.makeText(getContext(),"绑定成功",Toast.LENGTH_SHORT).show();
                   MyFragmentManger.getInstance().goBack(this);
                }
            }
        }



        WL.d("FloatNoticeFragment",response.toString());
    }

    private int deleteTaskId;





    @Override
    public void onClick(View view) {
        if(view ==backView){
            MyFragmentManger.getInstance().goBack(this);
        }else if(view == confirmBtn){
            String account = accountEdit.getText().toString().trim();
            String name = NameEdit.getText().toString().trim();
            if(TextUtils.isEmpty(account)){
                Toast.makeText(getContext(),"请输入支付宝账号",Toast.LENGTH_SHORT).show();
            }else if (TextUtils.isEmpty(name)){
                Toast.makeText(getContext(),"请输入支付宝姓名",Toast.LENGTH_SHORT).show();
            }else {
                deleteTaskId = HttpEngineApi.getInstance().redpackageaAlipay(account,name,requestCallbackHandler(FloatKefuResponseParams.class));
            }

        }
//        OnFinishActivityListener listener = getOnFinishActivityListener();
//        if (listener != null) {
//            listener.doFinishActivity(this);
//        }
    }


}
